import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/7 18:28
 * @description 循环到元素为1时，以该元素向右向下开始搜索是否还有1。
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int[][] findFarmland(int[][] land) {
        int m = land.length, n = land[0].length;
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if ( land[i][j] == 0) {
                    continue;
                }
                int row = i, col = j;
                // 向下探索
                while (row + 1 < m && land[row+1][j] == 1) {
                    row++;
                }
                // 向右探索
                while (col + 1 < n && land[row][col + 1] == 1) {
                    col++;
                }
                list.add(new int[]{i, j, row, col});

                // 以探索的区域值0
                for (int x = i; x <= row; x++) {
                    for (int y = j; y <= col ; y++) {
                        land[x][y] = 0;
                    }
                }
            }
        }
        return list.toArray(new int[0][0]);
    }
}
